package com.zhuzi.demojfoenix;

import com.jfoenix.controls.JFXDialog;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

public class HelloControllerBack {
    @FXML
    public JFXDialog dialog;
    @FXML
    public VBox context;
    @FXML
    private Label welcomeText;

    @FXML
    protected void onHelloButtonClick() {
        welcomeText.setText("Welcome to JavaFX Application!");
    }

    // @FXML
    private StackPane dialogStackPane;

    /**
     * 弹出JFXDialog弹窗
     */
    public void alert() {
        addDialogStackPane();
        dialog.setTransitionType(JFXDialog.DialogTransition.CENTER);
        dialog.show(dialogStackPane);
    }

    /**
     * 关闭JFXDialog弹窗
     */
    public void close() {
        dialog.close();
        dialogStackPane.getChildren().remove(dialog);
        context.getChildren().remove(dialogStackPane);
    }

    /**
     * 新增JFXDialog弹窗容器
     */
    private void addDialogStackPane() {
        dialogStackPane = new StackPane();
        dialogStackPane.setPrefHeight(context.getHeight());
        dialogStackPane.setPrefWidth(context.getWidth());
        context.getChildren().add(dialogStackPane);
    }

}
